/*
 * DataStore.h
 *
 *  Created on: 2017年3月5日
 *      Author: chuanjiang.zh
 */

#ifndef DATASTORE_H_
#define DATASTORE_H_

#include "BasicType.h"
#include "SharedPtr.h"
#include "ImageWatcherType.h"
#include <string>
#include <vector>
#include "json/json.h"

typedef std::vector< EventRecord >		EventRecordVector;
typedef std::vector< ImageRecord >		ImageRecordVector;
typedef std::vector< Json::Value >		JsonList;

class DataStore
{
public:
	static const size_t MAX_ROW = 1000;

public:
	virtual ~DataStore() {}

	virtual bool open(const std::string& path) =0;

    virtual void close() =0;

    virtual bool isOpen() =0;


    virtual bool execute(const std::string& sql) =0;

    virtual bool query(const std::string& sql, std::string& value) =0;

    virtual bool query(const std::string& sql, int& value) =0;

    virtual int update(const std::string& sql) =0;

    virtual bool query(const std::string& sql, Json::Value& json) =0;

    virtual bool query(const std::string& sql, JsonList& jsonList) =0;

    virtual bool queryToJson(const std::string& sql, std::string& text) =0;
    virtual bool querySomeToJson(const std::string& sql, std::string& text) =0;

    virtual bool update(const std::string& table, const Json::Value& json, const std::string& condition) =0;

    virtual bool insert(const std::string& sql, const std::string& table, long& id) =0;
    virtual bool insert(const std::string& table, const Json::Value& json) =0;
    virtual bool insert(const std::string& table, const Json::Value& json, long& id) =0;

    virtual bool replace(const std::string& table, const Json::Value& json) =0;

    virtual bool search(const std::string& table, const std::string& query, const std::string& condition, const std::string& order,
    			int offset, int limit, int& total, JsonList& jsonList) =0;



	virtual bool addEvent(EventRecord& record) =0;

	virtual bool removeEvent(int id) =0;

	virtual bool getEvent(int id, EventRecord& record) =0;

	virtual bool updateEvent(EventRecord& record) =0;

	virtual bool addImage(ImageRecord& record) =0;

	virtual bool removeImage(int id) =0;

	virtual bool getImage(int id, ImageRecord& record) =0;


	virtual bool findEvent(const char* filepath, EventRecord& record) = 0;

	virtual bool findImage(const char* filepath, ImageRecord& record) = 0;


	virtual int searchEvent(const char* company, const char* station, int num, time_t fromTime, time_t toTime, EventRecord* record, int size) =0;

	virtual bool removeEvents(const char* company, const char* station, int num, time_t fromTime, time_t toTime) =0;

	virtual int searchImage(const char* company, const char* station, int num, time_t fromTime, time_t toTime, ImageRecord* record, int size) =0;

	virtual bool removeImages(const char* company, const char* station, int num, time_t fromTime, time_t toTime) =0;


};

typedef std::shared_ptr< DataStore >    DataStorePtr;


#endif /* DATASTORE_H_ */
